#!/bin/bash
#
# Created by Pete Johnston, Eduserv for the SALDA project, 2011
#
#
# Adapted from the XSLT http://data.archiveshub.ac.uk/xslt/20110502/ead2rdf.xsl
# created by Pete Johnston, Eduserv for the LOCAH project, 2010-2011
#
# Copyright (c) 2011, Eduserv
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#    * Redistributions of source code must retain the above copyright
#      notice, this list of conditions and the following disclaimer.
#    * Redistributions in binary form must reproduce the above copyright
#      notice, this list of conditions and the following disclaimer in the
#      documentation and/or other materials provided with the distribution.
#    * Neither the name of Eduserv nor the
#      names of its contributors may be used to endorse or promote products
#      derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL EDUSERV BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# For Information see http://data.lib.sussex.ac.uk/data/mass-observation/
#
#
#
#
base='/home/libadmin/salda'
eadbase=$base/ead
rdfbase=$base/rdf
#saxondir='/home/saxonhe/9-3-0-5j/'
PATHS=("/")
for path in ${PATHS[@]}
do
  rm $rdfbase$path*.nt
  EADFILES=`ls $eadbase$path*.xml`
  for ead in $EADFILES
  do
#    echo $ead
    rdf=`echo "$ead" | sed 's,/ead/,/rdf/,g'`
#    echo $rdf
    java -jar $saxondir'saxon9he.jar' -s:$ead -xsl:http://pete.eduservlab.net/salda/xslt/ead2rdf.xsl -o:$rdf root=http://data.lib.sussex.ac.uk/archive/
    ttl=`echo "$rdf" | sed 's/.xml/.ttl/g'`
    rapper -i rdfxml -o turtle "$rdf" > "$ttl" 
    ntr=`echo "$rdf" | sed 's/.xml/.nt/g'`
    rapper -i rdfxml -o ntriples "$rdf" > "$ntr"
    pre=`echo "$rdf" | sed 's/.xml//g'` 
    split -l 15000 "$ntr" "$pre"-part-
    PARTS=`ls "$pre"-part-*`
    for p in $PARTS
    do
      mv "$p" "$p".nt
      echo "store $p.nt"
    done
#  read
  done
done
